package com.cn.intelligence.resetful.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.intelligence.pojo.TaotaoResult;
import com.cn.intelligence.resetful.service.ItemService;

@Controller
@RequestMapping("/Api/Product/")
public class ItemController {
	@Autowired
	public ItemService itemService;
	
	@RequestMapping("index")
	@ResponseBody
	public TaotaoResult getItemDesc(Long pro_id){
		TaotaoResult taotaoResult = new TaotaoResult();
		taotaoResult = itemService.selectProductDesc(pro_id);
		return taotaoResult;
	}
	/**
	 * 获取商品分类
	 * @param cartId
	 * @return
	 */
	@RequestMapping("category")
	@ResponseBody
	public TaotaoResult getCategory(Long cartId){
		TaotaoResult taotaoResult = new TaotaoResult();
		taotaoResult = itemService.getCategory(cartId);
		return taotaoResult;
	}
	/**
	 * 根据商品分类获取商品信息
	 */
	@RequestMapping("selectItemBycategory")
	@ResponseBody
	public TaotaoResult selectItemBycategory(String catId,String brandId,String ptype,int page){
		Long catIdLong = 0l;
		Long brandIdLong = 0l;
		if(catId !=null && !"".equals(catId) && !"undefined".equals(catId)){
			catIdLong = Long.parseLong(catId);
		}
		if(brandId !=null && !"".equals(brandId)&& !"undefined".equals(brandId)){
			brandIdLong = Long.parseLong(brandId);
		}
		if(catIdLong==0 && brandIdLong==0 &&"".equals(ptype)){
			return TaotaoResult.fail();
		}
		
		TaotaoResult taotaoResult = new TaotaoResult();
		taotaoResult = itemService.selectItemBycategory(catIdLong,brandIdLong,ptype,page);
		return taotaoResult;
	}
	
}
